/**
  * 关闭
 */

<template lang='pug'>
  Modal(v-model="isShowCloseModal" title="关闭" :closable="false" :mask-closable="false")
    Form(ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="125")
      FormItem(label="关闭原因：" prop="closedReason")
        Input.input-has-border(v-model="formValidate.closedReason" type="textarea" style="width:100%" clearable)
    template(slot="footer")
      Button(@click="cancel") 取消
      Button(type="info" :loading="loading" @click="handleSubmit") 确定
</template>

<script>
import HRDCCustomerApi from '@/api/HRDCCustomer.api.js'

export default {
  name: "StopCooperate",
  props: {
    // show: false,
    // handleId: String
  },
  data() {
    return {
      modalType: null,
      parentRow: null,
      loading: false,
      isShowCloseModal: false,
      formValidate: {
        closedReason: '' // 关闭原因
      },
      ruleValidate: {
        closedReason: [
          { required: true, message: '请填写关闭原因', trigger: 'blur' }
        ]
      }
    }
  },

  computed: {},

  mounted() {},

  methods: {
    cancel () {
      this.isShowCloseModal = false
    },

    show (row) {
      this.parentRow = row
      this.isShowCloseModal = true
    },
    
    handleSubmit () {
      console.log('点击确认, formValidate: ', this.formValidate, ', this.parentRow: ', this.parentRow, ', this.modalType: ', this.modalType)
      this.$refs.formValidate.validate((valid) => {
        if (valid) {
          HRDCCustomerApi.closeRequirement({
            id: this.modalType == 'A' ? this.parentRow.id : this.parentRow.requirementId,
            closedReason: this.formValidate.closedReason
          }).then((res) => {
            this.loading = false
            if (res.data.success) {
              this.isShowCloseModal = false;
              this.$Message.success('操作成功！')
              this.$refs.formValidate.resetFields();
              this.$emit('query')
            } else {
              this.$Message.error({
                content: res.data.message,
                duration: 10,
                closable: true
              })
            }
          })
        } else {
        }
      })
    }
  },

  watch: {

  }
};
</script>
<style lang='less' scoped>
.d-f-c{
  display: flex;
  align-items: flex-start;
  span{
    display: inline-block;
    width: 125px;
    padding-right: 12px;
  }
  .content{
    flex: 1;
  }
}
</style>